<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of db_customer
 *
 * @author user
 */
//constanta
define('TABLE_NAME','costumer');

class Db_customer extends Model{
    //put your code here
    
    function Db_customer(){
        parent::Model();
    }

    function retr_list(){ 
        $pesanan = $this->db->query("SELECT * FROM ". TABLE_NAME);
        $i = 0;
        foreach ($pesanan->result() as $hasil){
            $res[$i] = $hasil;
            $i++;
        }

        return $res;
    }

    function retr_id($id){
        $pesanan = $this->db->query("SELECT * FROM ". TABLE_NAME . " WHERE ID='". $id ."'");
        $hasil = $pesanan->row();
        return $hasil;
    }
    //insert
   function insert($nama, $nohp){
        $data = array(
                'nama' => $nama,
                'no_hp' => $nohp
            );

        $this->db->insert(TABLE_NAME, $data);
   }
    //update <<< diulang2 bagus ndak ini?
    function update2($column, $oldval, $newval){
        $this->db->query("UPDATE ". TABLE_NAME. " SET ". $column. "='$newval' WHERE ". $column. "='$oldval'");
    }
    function update($id,$no_hp,$nama){
        $this->db->query("UPDATE ". TABLE_NAME. " SET no_hp ='$no_hp', nama ='$nama' WHERE id =$id");
    }
    //delete
    function delete_where_nohp($val){
        $this->db->query("DELETE FROM ". TABLE_NAME. " WHERE nohp='$val'");
    }

    function delete_where_nama($val){
        $this->db->query("DELETE FROM ". TABLE_NAME. " WHERE nama='$val'");
    }

    function delete_where_id($val){
        $this->db->query("DELETE FROM ". TABLE_NAME. " WHERE ID='$val'");
    }
    
    function delete($n_val, $h_val){
        $this->db->query("DELETE FROM ". TABLE_NAME. " WHERE nama='$n_val' AND no_hp='$h_val'");
    }

}
?>
